﻿using AutoMapper;
using MediatR;
using SheepStorage.API.Application.Command.SheepPurchaseCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Application.CommandHandlers.SheepPurchaseHandler
{
    public class SheepPurchaseFillHandler:IRequestHandler<SheepPurchaseFillCommand,Results<SheepPurchase>>
    {
        private readonly ISheepPurchaseService _purchaseService;
        private readonly IMapper _mapper;

        public SheepPurchaseFillHandler(ISheepPurchaseService purchaseService,IMapper mapper)
        {
            _purchaseService = purchaseService;
            _mapper = mapper;
        }

        /// <summary>
        /// 获取羊只单个数据
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Results<SheepPurchase>> Handle(SheepPurchaseFillCommand request, CancellationToken cancellationToken)
        {
            var list=_mapper.Map<SheepPurchase>(await _purchaseService.GetSheepPurchaseInfo(request.PurchaseId));

            return Results<SheepPurchase>.DataResult(list);
        }
    }
}
